package com.osp.Graph;

import java.io.IOException;
import java.util.List;
import java.util.Scanner;

import javax.swing.JFrame;

import pl.owm.main.ModelCreator;

import com.osp.ProjectManager;
import com.osp.model.Employee;


public class MainGraph {
	private static Scanner scGraph = new Scanner(System.in);
	private static DataPlot plot = null;
	private static ProjectManager pm;
	private static Employee empToPrint;
	
	public static void ShowGraph() throws IOException, InterruptedException
	{	
		//plot.getJpg();
		plot = new DataPlot(empToPrint);	
		plot.showInFrame();
	}
	
	public static void main(String[] args) throws IOException, InterruptedException{
		ModelCreator mc = new ModelCreator();
		pm = mc.createModel();
		
		int retVal = -1;
		int newVal = -1;
		
		ShowMenu();
		do 
		{
			newVal = scGraph.nextInt();		
			if (newVal!=retVal)
			{
				switch (newVal) {
				case 1:
					scGraph.nextLine();
					System.out.println("Prosze wprowadzic nazwe pracownika");
					String userName = scGraph.nextLine();
					empToPrint = FindEmployee(userName);
					ShowGraph();
					break;
				case 3:
					ShowGraph();
					break;

				default:
					break;
				}
				
				ShowMenu();
			}
			retVal=newVal;
		}
		while (retVal!=0);
		System.out.println(retVal);
	}
	
	public static void ShowMenu()
	{
		System.out.println("=============================================");
		System.out.println("0 - zakoncz program");
		System.out.println("1 - Prosze wprowadzic Imie i Nazwisko pracownika");
		System.out.println("3 - Drukuj wykres dla pracownika");
	}
	
	public static Employee FindEmployee(String UserName)
	{
		List<Employee> employees = pm.getEmployees();
		
		for (int i =0; i <employees.size(); i++)
		{
			if (employees.get(i).getName().equals(UserName))
				return employees.get(i);
		}	
		return null;
	}
		
}
